#ifndef SQL_H
#define SQL_H

#include <QObject>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QDebug>
#include <QList>
#include <QDateTime>
#include "food.h"
#include "storage.h"
#include "remind.h"
#include "option.h"
#include "unit.h"
#include "foodtype.h"
class SQL : public QObject
{
    Q_OBJECT
public:
    explicit SQL(QObject *parent = nullptr);
    void open();
    void close();


    // 食物
    QList<Food> foodSearch(QString name,int size,int index);
    // 返回所有的非核心数据，即用户创建的食物信息
    QList<Food> foodUserData();
    // 将列表中的数据添加到数据库中
    void foodAdd(QList<Food> foods);
    // 清除所有的核心数据
    void foodClearCoreData();
    void foodClearUserData();
    // 添加食物
    void foodAdd(Food food);


    void unitClearCoreData();
    void unitAdd(Unit unit);
    void unitAdd(QList<Unit> units);

    void foodtypeClearCoreData();
    void foodtypeAdd(FoodType foodtype);
    void foodtypeAdd(QList<FoodType> foodtypes);


    // 存储
    QList<Storage> storageSearchAll();
    QList<Storage> storageUserData();
    void storageAdd(long user_id,long food_id,int amount);
    void storageAdd(QList<Storage> storages);
    void storageUpdate(long user_id,long food_id,int amount);
    void storageDelete(long user_id,long food_id);
    void storageClearUserData();
    // 提醒
    QList<Remind> remindSearchAll();
    QList<Remind> remindUserData();
    void remindAdd(long user_id,long food_id,int amount,QDate date);
    void remindAdd(QList<Remind> reminds);
    void remindUpdate(long id,int amount, QDate date);
    void remindDelete(long id);
    void remindClearUserData();

    // 操作
    QList<Option> optionSearchUncommitAll();
    QList<Option> optionSearchCommitAll();
    void optionCommit(long id);
    void optionCommit(QList<long> ids);
    void optionAdd(QList<Option> options);
    void optionAdd(Option option);
    void optionUpdate(long id,int amount,int direction);
    void optionDelete(long id);
    void optionDeleteAllCommit();

    QSqlDatabase database;
signals:

};

#endif // SQL_H
